package com.itheima.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
public class ReportData implements Serializable {
    private String reportDate;//当前日期,格式为yyyy-MM-dd
    private int todayNewMember;//今日新增会员数
    private int totalMember;//总会员数
    private int thisWeekNewMember;//本周新增会员数
    private int thisMonthNewMember;//本月新增会员数
    private int todayOrderNumber;//今日预约数
    private int todayVisitsNumber;//今日到诊数
    private int thisWeekOrderNumber;//本周预约数
    private int thisWeekVisitsNumber;//本周到诊数
    private int thisMonthOrderNumber;//本月预约数
    private int thisMonthVisitsNumber;//本月到诊数
    private List<HotSetmeal> hotSetmeals;//热门套餐

    //给每一个热门套餐设置占比
//    public void setHotSetmeals(List<HotSetmeal> hotSetmeals) {
//        double sum = 0;
//        for (HotSetmeal hotSetmeal : hotSetmeals) {
//            sum += hotSetmeal.getSetmeal_count();
//        }
//        for (HotSetmeal hotSetmeal : hotSetmeals) {
//            BigDecimal proportion = new BigDecimal(hotSetmeal.getSetmeal_count()).divide(new BigDecimal(sum), 4, BigDecimal.ROUND_HALF_UP);
//            hotSetmeal.setProportion(proportion.doubleValue());
//        }
//        this.hotSetmeals = hotSetmeals;
//    }


//    public List<HotSetmeal> getHotSetmeals() {
//        List<HotSetmeal> hotSetmealList = this.hotSetmeals;
//        double sum = 0;
//        for (HotSetmeal hotSetmeal : hotSetmealList) {
//            sum += hotSetmeal.getSetmeal_count();
//        }
//        for (HotSetmeal hotSetmeal : hotSetmealList) {
//            BigDecimal proportion = new BigDecimal(hotSetmeal.getSetmeal_count()).divide(new BigDecimal(sum), 4, BigDecimal.ROUND_HALF_UP);
//            hotSetmeal.setProportion(proportion.doubleValue());
//        }
//        return hotSetmealList;
//    }

    public List<HotSetmeal> getHotSetmeals() {
        double sum = 0;
        for (HotSetmeal hotSetmeal : hotSetmeals) {
            sum += hotSetmeal.getSetmeal_count();
        }
        for (HotSetmeal hotSetmeal : hotSetmeals) {
            BigDecimal proportion = new BigDecimal(hotSetmeal.getSetmeal_count()).divide(new BigDecimal(sum), 4, BigDecimal.ROUND_HALF_UP);
            hotSetmeal.setProportion(proportion.doubleValue());
        }
        return hotSetmeals;
    }
}
